package com.ice.netty.modbus.config;

import com.ice.netty.modbus.server.NettyTestServer;
import com.ice.remoting.NettyServerConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.context.annotation.Configuration;

@Slf4j
@Configuration
public class BikeNettyServerConfig implements ApplicationRunner, DisposableBean {

    @Autowired
    private NettyTestServer nettyTestServer;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        nettyTestServer.start();
    }


    @Override
    public void destroy() throws Exception {
        if (nettyTestServer != null) {
            nettyTestServer.stop();
        }
    }
}
